package logic

import (
	"context"
	"yuekaoHouse/house_srv/house"

	"yuekaoHouse/api/internal/svc"
	"yuekaoHouse/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseListLogic) HouseList(req *types.HouseListRequest) (resp *types.RegMsgResponse, err error) {
	// todo: 房源列表

	list, err := l.svcCtx.HouseSrv.HouseList(l.ctx, &house.HouseListRequest{
		Title:   req.Title,
		Page:    int64(req.Page),
		Size:    int64(req.Size),
		Address: req.Address,
	})
	if err != nil {
		return &types.RegMsgResponse{
			Cre:  -1,
			Mag:  "服务器错误",
			Data: nil,
		}, err
	}

	return &types.RegMsgResponse{
		Cre: 0,
		Mag: "查询成功",
		Data: map[string]interface{}{
			"List": list.HouseList,
		},
	}, err
}
